unit SUTrade;

interface
  type
    PTradeHandler = class
      private
        class var _Instance : PTradeHandler;
        constructor Create;overload;
        function SinGetTradePartner(Index: Byte): Cardinal;
        function SinGetCount: Byte;
        function SinGetTradePartnerName(Index: Byte): String;
        function SinIsTrading: Boolean;
      public
        class function GetInstance():PTradeHandler;
        //*************************************************************
        //* I think this is PREAOS No clue about..lol
        //*************************************************************
        //function GetTradeContainer(TradeNum, Num : Byte) : Cardinal;
        //function TradeCheck(TradeNum, Num : Byte) : Boolean;
        //*************************************************************
        function Confirm(SIndex:Byte):Boolean;
        function Cancel(SIndex:Byte):Boolean;

        property TradePartner[Index:Byte] : Cardinal    read SinGetTradePartner;
        property TradePartnerName[Index:Byte] : String  read SinGetTradePartnerName;

        property Count : Byte                           read SinGetCount;
        property IsTrading : Boolean                    read SinIsTrading;
    end;

implementation
  uses
    SUStealth;

{ PTradeHandler }

function PTradeHandler.Cancel(SIndex: Byte): Boolean;
var
  t : TSecureTrade;
  b : Byte;
begin
  Result := False;
  b := Count;
  if(b < SIndex)or(b = 0)then exit;
  Result := t.CancelTrade(SIndex);
end;

function PTradeHandler.Confirm(SIndex: Byte): Boolean;
var
  t : TSecureTrade;
  b : Byte;
begin
  Result := False;
  b := Count;
  if(b < SIndex)or(b = 0)then exit;
  t.ConfirmTrade(SIndex);
  Result := True;

end;

constructor PTradeHandler.Create;
begin
  //Unused
end;

class function PTradeHandler.GetInstance: PTradeHandler;
begin
  if not Assigned(_Instance) then _Instance := PTradeHandler.Create;
  Result := _Instance;
end;

function PTradeHandler.SinGetCount: Byte;
var
  t : TSecureTrade;
begin
  Result := t.GetTradeCount;
end;

function PTradeHandler.SinGetTradePartner(Index: Byte): Cardinal;
var
  t : TSecureTrade;
begin
  Result := t.GetTradeOpponent(Index);
end;

function PTradeHandler.SinGetTradePartnerName(Index: Byte): String;
var
  t : TSecureTrade;
begin
  Result := t.GetTradeOpponentName(Index);
end;

function PTradeHandler.SinIsTrading: Boolean;
var
  t : TSecureTrade;
begin
  Result := t.CheckTradeState;
end;

end.

